-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read certificate file ref from DCOD file #121
base: main
Are you sure you want to change the base?
Conversation
b777700
to
d22d90e
Compare
Fixes: web-eid#119 Signed-off-by: Raul Metsma <raul@metsma.ee>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All in all very nice code, was a pleasure to read - thanks for a job well done!
tag = *begin++; | ||
if ((tag & 0x1F) == 0x1F) { // Multi-byte tag | ||
if (!*this) { | ||
throw std::invalid_argument("Invalid TLV: Unexpected end of tag"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use THROW()
to get context info into the log, also the error message could be a little more precise:
throw std::invalid_argument("Invalid TLV: Unexpected end of tag"); | |
THROW(std::invalid_argument, "Invalid TLV: Multi-byte tag without second byte"); |
} | ||
|
||
if (!*this) { | ||
throw std::invalid_argument("Invalid TLV: Missing length field"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use THROW()
here as well.
if (length & 0x80) { // Extended length encoding | ||
auto num_bytes = uint8_t(length & 0x7F); | ||
if (num_bytes == 0 || num_bytes > 4 || std::distance(begin, end) < num_bytes) { | ||
throw std::invalid_argument("Invalid TLV: Incorrect extended length encoding"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use THROW()
here as well.
} | ||
|
||
if (std::distance(begin, end) < length) { | ||
throw std::invalid_argument("Invalid TLV: Insufficient value data"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use THROW()
here as well.
{ | ||
for (; tlv; ++tlv) { | ||
if (tlv.tag == tag) { | ||
if constexpr (sizeof...(tags) > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our coding standard requires using curly braces with if
:
if constexpr (sizeof...(tags) > 0) | |
if constexpr (sizeof...(tags) > 0) { |
namespace electronic_id | ||
{ | ||
|
||
struct TLV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a brief explanation that the constructor consumes the tag and length so that begin and end point to the value directly:
struct TLV | |
/** | |
* Represents a single Tag-Length-Value structure used in DER-encoded eID card files. | |
* | |
* The constructor parses the tag and length from the provided byte range, | |
* then adjusts its iterators so that `begin` and `end` reference only the value bytes. | |
* If the TLV is empty, `operator bool()` returns false. | |
*/ | |
struct TLV |
KeyInfo authKeyRef() const override; | ||
KeyInfo signKeyRef() const override; | ||
|
||
const byte_vector& readEF_File(byte_vector file, std::map<byte_vector, byte_vector> &cache) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs reformatting with clang-format.
WE2-1066
Fixes: #119
Signed-off-by: Raul Metsma raul@metsma.ee